(function() {
	module('Hanoi Tests');

	test('Setup OK', function() {
		ok(true);
	});

	test('Initial state', function() {
		var view = new TestView();
		var controller = new HanoiController(view);

		controller.startup();

		var expected = [];
		expected[0] = [ 3, 2, 1 ];
		expected[1] = [];
		expected[2] = [];

		deepEqual(view.state, expected);
	});

	test('onMove', function() {
		var view = new TestView();
		var controller = new HanoiController(view);

		controller.startup();
		var moved = controller.onMove(0, 1);
		ok(moved);

		var expected = [];
		expected[0] = [ 3, 2 ];
		expected[1] = [ 1 ];
		expected[2] = [];

		deepEqual(view.state, expected);
	});

	test('not allowed move ', function() {
		var view = new TestView();
		var controller = new HanoiController(view);

		controller.startup();
		var moved = controller.onMove(0, 1);
		ok(moved);
		moved = controller.onMove(0, 1);
		ok(!moved);

		var expected = [];
		expected[0] = [ 3, 2 ];
		expected[1] = [ 1 ];
		expected[2] = [];

		deepEqual(view.state, expected);
	});

	test('a solution ', function() {
		var view = new TestView();
		var controller = new HanoiController(view);

		controller.startup();
		controller.onMove(0, 2);
		controller.onMove(0, 1);
		controller.onMove(2, 1);
		controller.onMove(0, 2);
		controller.onMove(1, 0);
		controller.onMove(1, 2);
		controller.onMove(0, 2);

		ok(view.onSolvedCalled);
	});

	function TestView() {
		this.onSolvedCalled = false;
	}

	TestView.prototype.init = function(controller) {
	};

	TestView.prototype.update = function(state) {
		var newState = [];
		for ( var i = 0; i < state.length; i++) {
			newState.push(state[i].slice(0));
		}
		this.state = newState;
	};

	TestView.prototype.onSolved = function() {
		this.onSolvedCalled = true;
	};
}());